package com.common.basis.entity;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author wangguochao
 */
@Data
public class User implements UserDetails, Serializable {
    private static final long serialVersionUID = 8848L;
    private String password;
    private String username;
    private Set<GrantedAuthority> authorities;
    private String tenantId;
    private String userId;
    private boolean accountNonExpired;
    private boolean accountNonLocked;
    private boolean credentialsNonExpired;
    private boolean enabled;

    public void setAuthorities(Set<Map<String, String>> authorities) {
        Set<GrantedAuthority> set = new HashSet<>();
        for (Map<String, String> authority : authorities) {
            GrantedAuthority grantedAuthority = new SimpleGrantedAuthority(authority.get("authority"));
            set.add(grantedAuthority);
        }
        this.authorities = set;
    }


}
